const fs = require('fs')
const inquirer = require('inquirer');
const ejs = require('ejs')
inquirer
  .prompt([
    {
      type: 'input',
      name: 'name',
      message: 'project name',
      default: 'vue-demo'
    },
    {
      type: 'checkbox',
      name: 'modules',
      message: 'select your modules',
      choices: [
        {
          name: 'vue-router',
        },
        {
          name: 'vuex',
        }
      ]
    }
  ])
  .then(answers => {
    for (const key in answers) {
      switch (key) {
        case 'name':
          fs.mkdir(answers[key], (err) => {
          })
          break
        case 'modules':
          const modules = answers[key]
          const useVueRouter = modules.includes('vue-router')
          const useVuex = modules.includes('vuex')
          ejs.renderFile('./templates/app.js', {
            useVueRouter,
            useVuex
          }, (err, str) => {
            if (err) {
              console.log(err)
              return
            }
            fs.writeFileSync(`${answers.name}/app.js`, str)
          })
          break;
        default:
          break;
      }
    }
    // Use user feedback for... whatever!!
  })